package com.jiaquyun.jcps.ui.main

import android.app.Activity
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.amap.api.navi.AMapNavi
import com.amap.api.navi.AMapNaviListener
import com.amap.api.navi.AMapNaviViewListener
import com.amap.api.navi.enums.NaviType
import com.amap.api.navi.enums.TravelStrategy
import com.amap.api.navi.model.*
import com.jiaquyun.jcps.R
import kotlinx.android.synthetic.main.activity_route2.*


class RouteActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewListener {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, RouteActivity::class.java)
            activity.startActivity(intent)
        }
    }


    protected var mAMapNavi: AMapNavi? = null

//    override val layoutResId: Int
//        get() = R.layout.activity_route
//
//    override fun initView() {
//        mAMapNavi = AMapNavi.getInstance(applicationContext)
//        mAMapNavi?.addAMapNaviListener(this)
//    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_route2)
        mAMapNavi = AMapNavi.getInstance(applicationContext)
        mAMapNavi?.addAMapNaviListener(this)
        mAMapNaviView.onCreate(savedInstanceState)
        mAMapNaviView.setAMapNaviViewListener(this)



        val options = mAMapNaviView.viewOptions
        options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_app_position));
//        options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_app_position));
//        options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_app_position));
//        options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
        options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_app_loca_1));
        options.isSettingMenuEnabled = true
        options.isTrafficLine = false
        options.isLayoutVisible = false
        options.isAutoDisplayOverview = true
        mAMapNaviView.viewOptions = options

        mAMapNavi?.setUseInnerVoice(true,true)
        mAMapNavi?.startGPS()
        // 起点信息

//        // 起点信息
//        val start = NaviLatLng(39.993308, 116.473199)
////        val start = NaviPoi("故宫博物馆", null, "B000A8UIN8")
//        // 终点信息
//        // 终点信息
//        val end = NaviLatLng(39.917834, 116.397036)
////        val end = NaviPoi("北京大学", null, "B000A816R6")
//        // 经纬度算路
//        // 经纬度算路
//        mAMapNavi?.calculateRideRoute(start,end)

//        mAMapNaviView.setOnMapTouchListener {
//            nestedScrollView.requestDisallowInterceptTouchEvent(true)
//        }
//        mAMapNaviView.map.uiSettings.setAllGesturesEnabled(false)
    }

    override fun onResume() {
        super.onResume()
        mAMapNaviView.onResume()
    }

    override fun onPause() {
        super.onPause()
        mAMapNaviView.onPause()
//
//        停止导航之后，会触及底层stop，然后就不会再有回调了，但是讯飞当前还是没有说完的半句话还是会说完
//        mAMapNavi.stopNavi();
    }

    override fun onDestroy() {
        super.onDestroy()
        mAMapNaviView.onDestroy()
        //since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
        mAMapNavi?.stopNavi()
        mAMapNavi?.destroy()
    }

    override fun onNaviInfoUpdate(p0: NaviInfo?) {

    }

    override fun onCalculateRouteSuccess(p0: IntArray?) {

    }

    override fun onCalculateRouteSuccess(p0: AMapCalcRouteResult?) {
        mAMapNavi?.startNavi(NaviType.GPS)
    }

    override fun onCalculateRouteFailure(p0: Int) {

    }

    override fun onCalculateRouteFailure(p0: AMapCalcRouteResult?) {

    }

    override fun onServiceAreaUpdate(p0: Array<out AMapServiceAreaInfo>?) {

    }

    override fun onGpsSignalWeak(p0: Boolean) {

    }

    override fun onEndEmulatorNavi() {

    }

    override fun onArrivedWayPoint(p0: Int) {

    }

    override fun onArriveDestination() {

    }

    override fun onPlayRing(p0: Int) {

    }

    override fun onTrafficStatusUpdate() {

    }

    override fun onGpsOpenStatus(p0: Boolean) {

    }

    override fun updateAimlessModeCongestionInfo(p0: AimLessModeCongestionInfo?) {

    }

    override fun showCross(p0: AMapNaviCross?) {

    }

    override fun onGetNavigationText(p0: Int, p1: String?) {

    }

    override fun onGetNavigationText(p0: String?) {

    }

    override fun updateAimlessModeStatistics(p0: AimLessModeStat?) {

    }

    override fun hideCross() {

    }

    override fun onInitNaviFailure() {

    }

    override fun onInitNaviSuccess() {

        // 起点信息

        // 起点信息
        val start = NaviLatLng(39.993308, 116.473199)
//        val start = NaviPoi("故宫博物馆", null, "B000A8UIN8")
        // 终点信息
        // 终点信息
        val end = NaviLatLng(39.917834, 116.397036)
//        val end = NaviPoi("北京大学", null, "B000A816R6")
        // 经纬度算路
        // 经纬度算路
        mAMapNavi?.calculateRideRoute(start,end)
    }

    override fun onReCalculateRouteForTrafficJam() {

    }

    override fun updateIntervalCameraInfo(
        p0: AMapNaviCameraInfo?,
        p1: AMapNaviCameraInfo?,
        p2: Int
    ) {

    }

    override fun hideLaneInfo() {

    }

    override fun showModeCross(p0: AMapModelCross?) {

    }

    override fun updateCameraInfo(p0: Array<out AMapNaviCameraInfo>?) {

    }

    override fun hideModeCross() {

    }

    override fun onLocationChange(p0: AMapNaviLocation?) {

    }

    override fun onReCalculateRouteForYaw() {

    }

    override fun onStartNavi(p0: Int) {

    }

    override fun notifyParallelRoad(p0: Int) {

    }

    override fun OnUpdateTrafficFacility(p0: Array<out AMapNaviTrafficFacilityInfo>?) {

    }

    override fun OnUpdateTrafficFacility(p0: AMapNaviTrafficFacilityInfo?) {

    }

    override fun onNaviRouteNotify(p0: AMapNaviRouteNotifyData?) {

    }

    override fun showLaneInfo(p0: Array<out AMapLaneInfo>?, p1: ByteArray?, p2: ByteArray?) {

    }

    override fun showLaneInfo(p0: AMapLaneInfo?) {

    }


    override fun onNaviTurnClick() {

    }

    override fun onScanViewButtonClick() {

    }

    override fun onLockMap(p0: Boolean) {

    }

    override fun onMapTypeChanged(p0: Int) {

    }

    override fun onNaviCancel() {

    }

    override fun onNaviViewLoaded() {

    }

    override fun onNaviBackClick(): Boolean {
        return false
    }

    override fun onNaviMapMode(p0: Int) {

    }

    override fun onNextRoadClick() {

    }

    override fun onNaviViewShowMode(p0: Int) {

    }

    override fun onNaviSetting() {

    }


}